package dao

import (
	"errors"
	"user_srv/handler/models"
)

func AddAddress(userId int32, address string) (uint64, error) {
	a := models.Address{
		UserId:  userId,
		Address: address,
	}
	if err := a.Create(); err != nil {
		return 0, errors.New("添加新地址失败：" + err.Error())
	}
	return a.Id, nil
}
func UpdateAddress(id uint64, address string) error {
	a := models.Address{
		Id:      id,
		Address: address,
	}
	if err := a.Updates(); err != nil {
		return errors.New("修改地址失败：" + err.Error())
	}
	return nil
}
func DeleteAddress(id uint64) error {
	a := models.Address{
		Id: id,
	}
	if err := a.Delete(); err != nil {
		return errors.New("删除地址失败：" + err.Error())
	}
	return nil
}
